package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entry.Message;
import com.example.demo.entry.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface MessageMapper extends BaseMapper<Message> {
    @Select("select * from message where username = #{username}")
    List<Message> selectByUsername(String username);
    @Select("select * from message")
    @Results(
            {
                    @Result(column = "id",property = "id"),
                    @Result(column = "content",property = "content"),
                    @Result(column = "username",property = "username"),
                    @Result(column = "username",property = "user",javaType = User.class,
                            one  = @One(select = "com.example.demo.mapper.UserMapper.selectByUsername"))
            }
    )
    public List<Message> selectAllMessagesAndUser();
}
